package cn.btks.resultintegration.rule.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.resultintegration.rule.pojo.ProhibitProject;
import cn.btks.resultintegration.rule.pojo.ProjectCategory;
import cn.btks.resultintegration.rule.service.ProjectCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijun
 * @Date 2021/2/19 11:05
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/rule")
@Api(tags = "规则模块")
@Validated
public class ProjectCategoryController {

    @Autowired
    ProjectCategoryService projectCategoryService;

    @GetMapping("/projectCategory/findById/{id}")
    @ApiOperation("根据三级ID查询环境影响评价分类管理名录三级信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "三级目录IDID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByCounty(@PathVariable("id") Long id) {
        ProjectCategory projectCategory = projectCategoryService.findById(id);
        return projectCategory != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), projectCategory) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/projectCategory/findAllProjectCategory")
    @ApiOperation("查询所有环境影响评价分类管理名录（项目类别-所属环评类别下的子类）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllProjectCategory() {
        List<ProjectCategory> projectCategoryList = projectCategoryService.findAllProjectCategory();
        return projectCategoryList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), projectCategoryList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/projectCategory/findAllByCategorySecondId/{categoryId}")
    @ApiOperation("根据环评类别二级目录ID查询其下子类")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "categoryId", value = "所属二级目录的ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByCategorySecondId(@PathVariable("categoryId") Long categoryId) {
        List<ProjectCategory> projectCategoryList = projectCategoryService.findAllByCategorySecondId(categoryId);
        return projectCategoryList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), projectCategoryList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
